package br.edu.oxente.buzz.entity;

import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Nigini A. Oliveira - ensino@nigini.com.br
 */
public class Post {

	private User user;
	private String text;
	private List<Comment> comments;
	private List<Vote> votes;

	public Post(User user, String text) {
		if (user == null || text == null) {
			throw new IllegalArgumentException("Nor user, nor text can be NULL.");
		}
		this.user = user;
		this.text = text;
		this.comments = new LinkedList<Comment>();
		this.votes = new LinkedList<Vote>();
	}

	public String getText() {
		return this.text;
	}

	public List<Comment> getComments() {
		return this.comments;
	}

	public void insertComment(Comment comment) {
		this.comments.add(comment);
	}

	public void insertVote(Vote vote) {
		this.votes.add(vote);
	}

	public List<Vote> getVotes() {
		return this.votes;
	}

	@Override
	public boolean equals(Object o) {
		if (o instanceof Post) {
			Post p = (Post) o;
			boolean equal = user.equals(p.user);
			equal &= text.equals(p.text);
			return equal;
		}
		return false;
	}
}
